using System.Collections.Generic;
using System.Text;
using UnityEngine;

namespace CGF
{
    public static class IPHelper
    {
        public static async CTask<bool> IsIndiaIP(string ip)
        {
            //尝试第一家
            var rsp = await HttpHelper.Get($"https://api.ipbase.com/v1/json/{ip}");
            if (rsp.success)
            {
                var json = LitJson.JsonMapper.ToObject(rsp.text);
                return (string)json["country_code"] == "IN";
            }

            //尝试第二家
            rsp = await HttpHelper.Get($"http://ip-api.com/json/{ip}");
            if (rsp.success)
            {
                var json = LitJson.JsonMapper.ToObject(rsp.text);
                return (string)json["countryCode"] == "IN";
            }

            //尝试第三家
            rsp = await HttpHelper.Get($"http://ipinfo.io/{ip}/json");
            if (rsp.success)
            {
                var json = LitJson.JsonMapper.ToObject(rsp.text);
                return (string)json["country"] == "IN";
            }

            //Common.Log2Net($"Check IP Failed: {rsp.text}");
            return false;
        }
    }
}